{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#### import arcpy\n",
    "import arcpy.mapping as mp\n",
    "import pandas as pd\n",
    "import sys\n",
    "import shutil\n",
    "import os\n",
    "import numpy \n",
    "import math\n",
    "reload(sys)\n",
    "sys.setdefaultencoding('utf-8')\n",
    "\n",
    "\n",
    "mxd = arcpy.mapping.MapDocument('CURRENT')\n",
    "lsd = mp.ListDataFrames(mxd)\n",
    "\n",
    "\n",
    "path = os.getcwd().decode('gbk').encode('utf-8').replace(\"演替图\",\"基础\")\n",
    "savelist = []\n",
    "path = path.decode(\"utf8\").encode('gbk')\n",
    "for root,dirs,files in os.walk(path):        \n",
    "    for file in files:       \n",
    "            if file.endswith(\".shp\"):\n",
    "                savelist.append(os.path.join(root,file))\n",
    "for df in lsd :\n",
    "    for layer in mp.ListLayers(df):\n",
    "        if (\"area\" in layer.name and \"poly\" not in layer.name) or (\"地域\" in layer.name and \"图斑\" not in layer.name):\n",
    "            pointname = layer.name.replace(\"area\",\"地域\").replace(\"type\",\"类型\").decode(\"utf8\").encode('gbk')\n",
    "            for i in savelist:\n",
    "                if (i.endswith(\"_点.shp\".decode(\"utf8\").encode('gbk')) and pointname in i) or i.endswith(pointname+\".shp\"):\n",
    "                    layer.replaceDataSource (\"\\\\\".join(c for c in i.split(\"\\\\\")[:-1]), \"SHAPEFILE_WORKSPACE\",i.split(\"\\\\\")[-1],False)\n",
    "                    shpname = layer.name\n",
    "        elif (\"area\" in layer.name and \"poly\" in layer.name) or (\"地域\" in layer.name and \"图斑\" in layer.name):\n",
    "            polyname = layer.name.replace(\"area\",\"地域\").replace(\"type\",\"类型\").replace(\"poly_\",\"\").decode(\"utf8\").encode('gbk')\n",
    "            for i in savelist:\n",
    "                if (i.endswith(\"_图斑.shp\".decode(\"utf8\").encode('gbk')) and pointname in i) or i.endswith(layer.name.decode(\"utf8\").encode('gbk') + \".shp\"):\n",
    "                    layer.replaceDataSource (\"\\\\\".join(c for c in i.split(\"\\\\\")[:-1]), \"SHAPEFILE_WORKSPACE\",i.split(\"\\\\\")[-1],False)\n",
    "\n",
    "with arcpy.da.UpdateCursor(shpname,[\"class1\"]) as cursor:\n",
    "    for row in cursor:\n",
    "        row[0] = \"1\"\n",
    "        cursor.updateRow(row)     \n",
    "        \n",
    "   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
